'use strict';
/**
 * Created by FreezeSoul on 2015/10/16.
 */
define([
        'angular',
        'app/modules/dictionary/define'
    ],
    function (angular) {
        angular.module('ad.dictionary')
            .directive('dictionaryCodeToName', ['_', 'adDictionaryService', function (_, service) {
                return {
                    template: '<span>{{dictionaryName}}</span>',
                    scope: {
                        dictionaryCode: '='
                    },
                    link: function ($scope, $elm, $attrs, $ctrl) {
                        var defaultType = "默认类型";
                        if($scope.dictionaryCode === defaultType){
                            $scope.dictionaryName = defaultType;
                        }else{
                            service.getByCode($scope.dictionaryCode).then(function (data) {
                                var obj = angular.fromJson(data);
                                if (obj.result == 'success') {
                                    $scope.dictionaryName = obj.data.dictionaryName === undefined ? $scope.dictionaryCode : obj.data.dictionaryName;
                                }
                            });
                        }
                    }
                };
            }
            ]);
    });